package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.dto.TestProductDetailRequest;
import com.cskaoyan.shopping.dto.TestProductDetailResponse;
import com.cskaoyan.shopping.service.ITestProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther cskaoyan
 * @date 2022/6/16:17:39
 */
@RestController
public class TestProductDetailController {

    @Autowired
    ITestProductDetailService testProductDetailService;

    @GetMapping("/shopping/test")
    public ResponseData testGetProductDetail(Long productId) {

        TestProductDetailRequest request = new TestProductDetailRequest();
        request.setProductId(productId);

        // 调用service处理请求
        TestProductDetailResponse response = testProductDetailService.testGetProductDetail(request);

        if (ShoppingRetCode.SUCCESS.getCode().equals(response.getCode())) {
            // 执行成功，直接返回前端需要的数据
            return new ResponseUtil().setData(response.getProductDetailDto());
        }
        // 调用失败
        return  new ResponseUtil().setErrorMsg(response.getMsg());
    }
}
